//
//  ViewController.swift
//  functional
//
//  Created by LimitLiu on 2019/1/31.
//  Copyright © 2019 LimitLiu. All rights reserved.
//

import UIKit

class ViewController: UITableViewController {
    
    private lazy var viewModel: [String] = ["first class value", "functional filter", "higher-order function", "geometry scene"]
    private var table: UITableView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        table = UITableView(frame: view.frame)
        table.dataSource = self
        table.delegate = self
        view.addSubview(table)
        table.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
    }
}

extension ViewController {
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return viewModel.count
    }
    
    override func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = (tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)) as UITableViewCell
        cell.textLabel?.text = viewModel[indexPath.row]
        return cell
    }
    
    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let tmp = viewModel[indexPath.row]
        switch tmp {
        case "first class value":
            let firstClazzValue = FirstClassValue()
            navigationController?.pushViewController(firstClazzValue, animated: true)
        case "functional filter":
            let liuFilter = LIUFilter()
            navigationController?.pushViewController(liuFilter, animated: true)
        case "higher-order function":
            let highOrderFunction = HigherOrderFunction()
            navigationController?.pushViewController(highOrderFunction, animated: true)
        case "geometry scene":
            let geometryScene = GeometryScene()
            navigationController?.pushViewController(geometryScene, animated: true)
        default:
            print("Failed to push view controller")
        }
    }
}
